package com.bangmai.api;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.proxy.jdbc.JdbcParameter.TYPE;
import com.bangmai.constant.Header;
import com.bangmai.service.CustomsService;
import com.bangmai.util.XmlUtil;
import com.bangmai.view.MessageBean;
import com.sun.tools.classfile.Annotation.element_value;
@RequestMapping("/customs")
@Controller
public class CustomsController {
	@Resource
	private CustomsService customsService;
	@RequestMapping(value="createAndSendXml",method=RequestMethod.GET)
	@ResponseBody
	public MessageBean createAndSendXml(){
		MessageBean messageBea=new MessageBean();
		try {
			customsService.createAndSendPacket(2);
			messageBea.setMsg("报文创建并发送成功");
			messageBea.setCode(Header.STATUS_SUCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			messageBea.setMsg(e.getMessage());
			messageBea.setCode(Header.STATUS_FATAL_ERROR);
		}
		
		return messageBea;
	}
	@RequestMapping(value="receivePacket",method=RequestMethod.GET)
	@ResponseBody
	public  MessageBean receivePacket(int type){
		MessageBean messageBean = new MessageBean();
		try {
			customsService.receivePacket(type);
			
			messageBean.setCode(Header.STATUS_SUCESS);
			messageBean.setMsg("下载成功");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			messageBean.setCode(Header.STATUS_FAILED);
			messageBean.setMsg(e.getMessage());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			messageBean.setCode(Header.STATUS_FATAL_ERROR);
			messageBean.setMsg(e.getMessage());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			messageBean.setCode(Header.STATUS_FATAL_ERROR);
			messageBean.setMsg(e.getMessage());
		}
		
		
		
		return messageBean;
		
		
		
	}
	@RequestMapping(value="analysepacket",method=RequestMethod.GET)
	@ResponseBody
	public  MessageBean analysepacket(){
		MessageBean messageBean=new MessageBean();
		
		try {
			customsService.analysepacket(1);
			messageBean.setMsg("解析成功");
			messageBean.setCode(Header.STATUS_SUCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			messageBean.setMsg(e.getMessage());
			messageBean.setCode(Header.STATUS_FATAL_ERROR);
		}
		return messageBean;
		
		
	}
	

}
